package com.yanqu.road.server.cmd.activity.dunhuangshiku;

import com.yanqu.road.entity.activity.seasontask.SeasonTaskConditionData;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.log.LogDunHuangShiKuExploreEvent;
import com.yanqu.road.pb.dunhuangshiku.DunHuangShiKuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.dunhuangshiku.DunHuangShiKuMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.date.DateHelper;

import java.math.BigInteger;

/**
 * @Description
 * @Author cwq
 * @Data 2021/4/20 22:08
 */
@Cmd(code = GameProtocol.S_DUN_HUANG_SHI_KU_EXPLORE_FROM_CROSS, desc = "敦煌石窟探索 跨服返回区服 协议")
public class DunHuangShiKuExploreFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DunHuangShiKuProto.DunHuangShiKuExploreToGameServerMsg req = DunHuangShiKuProto.DunHuangShiKuExploreToGameServerMsg.parseFrom(packet.getBytes());
        DunHuangShiKuProto.DunHuangShiKuExploreRespMsg toClientMsg  = req.getToClientMsg();
        if(toClientMsg.getRet() == 0){
            // 加日志
            AutoLogMgr.add(new LogDunHuangShiKuExploreEvent(DunHuangShiKuMgr.activityInfo.getActivityId(),player.getUserId(),req.getTeamId(),req.getRegionId(),toClientMsg.getEventId(),req.getEventType(),req.getOleValue(),req.getNewValue()));
        }
        // 触发事件
        int value = req.getOleValue() - req.getNewValue();
        SeasonTaskConditionData data = new SeasonTaskConditionData(BigInteger.valueOf((long)DunHuangShiKuMgr.activityInfo.getType()), BigInteger.valueOf((long)value));
        player.notifyListener(eGamePlayerEventType.DunHuangCostStaminaTask.getValue(), data);
        player.sendPacket(ClientProtocol.U_DUN_HUANG_SHI_KU_EXPLORE, toClientMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {
    }
}
